# 百度搜索面向对象
import time
from selenium import webdriver
from selenium.webdriver.common.by import By


class TestCase:
    def __init__(self):
        # 初始化,打开Chrome浏览器
        self.driver = webdriver.Chrome()

    def get_baidu(self):
        # 请求百度网址
        self.driver.get('https://www.baidu.com')

        # 停留2秒后,搜索框输入查询内容
        time.sleep(2)
        self.driver.find_element(By.ID, 'kw').send_keys('天气预报')

        # 停留2秒后,点击搜索按钮
        time.sleep(2)
        self.driver.find_element(By.ID, 'su').click()

    def get_so(self):
        # 请求360搜索网址
        self.driver.get('https://www.so.com')

        time.sleep(2)
        # 搜索框输入查询内容
        self.driver.find_element(By.ID, 'input').send_keys('天气预报')

        time.sleep(2)
        # 点击搜索按钮
        self.driver.find_element(By.ID, 'search-button').click()

    def quit(self, seconds=3):
        # 默认停留3秒退出
        time.sleep(seconds)
        self.driver.quit()


if __name__ == '__main__':
    # 创建对象case
    case = TestCase()
    # case.get_baidu()
    case.get_so()
    case.quit()
